package com.boot.system.controller;

import com.boot.common.anno.AnnoLog;
import com.boot.common.anno.RepeatSubmit;
import com.boot.common.result.Result;
import com.boot.system.service.MenuService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequiredArgsConstructor
@RestController
@RequestMapping("/menu")
public class MenuController {

    private final MenuService menuService;

    @AnnoLog(value = "菜单新增")
    @RepeatSubmit
    @PostMapping("/add")
    public Result<?> addMenu(@RequestBody Map<String, Object> dataParam) {
        return menuService.addMenu(dataParam);
    }

    @AnnoLog(value = "菜单修改")
    @RepeatSubmit
    @PostMapping("/update")
    public Result<?> updateMenu(@RequestBody Map<String, Object> dataParam) {
        return menuService.updateMenu(dataParam);
    }

    @AnnoLog(value = "菜单删除")
    @RepeatSubmit
    @PostMapping("/delete")
    public Result<?> deleteMenu(@RequestBody Map<String, Object> dataParam) {
        return Result.success(menuService.deleteMenu(Long.valueOf(dataParam.get("id").toString())));
    }

    @AnnoLog(value = "菜单列表")
    @PostMapping("/list")
    public Result<?> menuList(@RequestBody Map<String, Object> queryParam) {
        return Result.success(menuService.getMenuList(queryParam));
    }

    @AnnoLog(value = "菜单树")
    @GetMapping("/tree")
    public Result<?> deptTree() {
        return Result.success(menuService.getMenuTree());
    }

    @AnnoLog(value = "菜单批量设置角色")
    @PostMapping("/setRole")
    public Result<?> setRole(@RequestBody Map<String, Object> dataParam){
        return Result.success(menuService.setRole(dataParam));
    }

}
